<?php
class MessageModel extends Model {
	
	public function addMessage($map){
		//获取用户信息
		$user  = getMember();
		$map['dataid']  = $user['id'];
		$map['tableid'] = $user['type'];
		
		//获取城市信息
		$query = session(C('USER_SELECT_CITY'));
		$map['city']     = $query['cityid'];
		$map['addtime']  = time();
		$data = $this->add($map);
		
		return $data;
	}
	
	public function mesgselect($map){
		
		$desc     = $map['orderDirection'];
		$order    = $map['orderName'];
		$pageNum  = $map['pageNum'];
		$nowPage  = $map['nowPage'];
		$restid   = $map['restid'];
		$where    = $map['where'];
		 
		if($where){
			foreach ($where as $k=>$v){
				if($v){
					$map[$k] = $v;
				}
			}
		}
		 
		$map['isdel'] = 2 ;
		$con = $order.' '.$desc;
		
		$data = $this->pageSelect($map,$pageNum,$nowPage,$con);
	
		return $data;
	}
	
	/**
	 * 分页公共方法
	 * @access private
	 * @param string   $table    表名
	 * @param array    $map      查询条件
	 * @param string   $order    结果排序
	 * @param int      $pageNum  每页数量
	 * @param int      $nowPage  当前页数
	 * @return array
	 */
	private function pageSelect($map,$pageNum,$nowPage,$con){
	
		$count = $this->where($map)->count();
	
		$list  = $this->where($map)->order($con)->page($nowPage.','.$pageNum)->select();
		//echo $model->getLastSql();
		return array("count"=>$count, "list"=>$list);
	}
	
	/**
	 * 批量删除留言
	 */
	public function msgDel($val){
	
		if($val){
			$map['id']    = $val['id'];
			$map['isdel'] = 1;
			$data = $this->save($map);
		}
		return $data;
	}
	
	/**
	 * 批量删除菜品
	 */
	public function msgDelall($val){
		
		if($val){
			$idArr = explode(',',$val);
			foreach($idArr as $k=>$v){
			
				$map['id']    = $v;
				$map['isdel'] = 1;
				$data = $this->save($map);
			}
		}
		return $data;
	}
}
?>